import { t as $t } from '@src/locales'
import { QualityInfoTypeEnum, QualityInfoStateEnum } from '@model/enum/QualityInfoEnum'

type productTypeQualityTimeOptionUnit = '年'|'月'
interface productTypeQualityTimeOptionUnitOptions {
  text: string,
  value: productTypeQualityTimeOptionUnit,
}

export function getProductTypeQualityTimeOptions():productTypeQualityTimeOptionUnitOptions[] {
  return [
    {
      text: $t('common.time.month'),
      value: '月' 
    },
    {
      text: $t('common.time.year'),
      value: '年'
    }
  ]
}

export const getProductTypeQualityTimeText = (value: string, num: number|string) => {
  const varObj = {num}
  const valueObj = {
    '年': $t('common.base.aboutTime.manyYears', varObj),
    '月': $t('common.base.aboutTime.manyMonths', varObj),
  }
  return valueObj[value as productTypeQualityTimeOptionUnit] || value
}

export const getProductQualityStatusText = (value: string) => {
  const In = $t('common.base.warranty')
  const Out = $t('common.base.surrender')
  const valueObj = {
    In,
    [QualityInfoStateEnum.In]: In,
    Out,
    [QualityInfoStateEnum.Out]: Out,
  }
  return valueObj[value as keyof typeof valueObj] || value
}

export const getQualityInfoPeriodFieldText = (value: string) => {
  const Auto = $t('common.quality.type.auto')
  const Manual = $t('common.quality.type.manual')
  const valueObj = {
    Auto,
    [QualityInfoTypeEnum.Auto]: Auto,
    Manual,
    [QualityInfoTypeEnum.Manual]: Manual
  }
  return valueObj[value as keyof typeof valueObj] || value
}